package net.starwifi.duobao.service.impl;

import net.starwifi.duobao.SettingUtils;
import net.starwifi.duobao.service.SettingService;
import net.starwifi.duobao.service.WXUserService;
import net.starwifi.wx.api.UserAPI;
import net.starwifi.wx.dto.UserInfoByCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2016/1/27.
 */
@Service
public class WXUserServiceImpl implements WXUserService {

    @Autowired
    SettingService settingService;


    public String getUserAuthUrl(String redirectUri,String scope,String state){
        String appId= SettingUtils.get("wx_appid");
        return UserAPI.getUserAuthUrl(appId,redirectUri,"code",scope,state);
    }

    public UserInfoByCode getUserInfo(String code){
        String appId=SettingUtils.get("wx_appid");
        String appSecret=SettingUtils.get("wx_appsecret");
        String wBack=UserAPI.getUserAccessToken(appId,appSecret,code);
        return UserInfoByCode.fromJson(wBack);
    }

}
